#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int creat(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char buffer[1024];
  int srcfd, dstfd;
  int count;
  if (argc != 3) {
    fprintf(stderr, "Errore \n");
    return -1;
  }
  if ((srcfd = open(argv[1], O_RDONLY)) == -1) {
    fprintf(stderr, "Errore sorgente \n");
    return -2;
  }
  if ((dstfd = creat(argv[2], O_RDWR)) == -1) {
    fprintf(stderr, "Errore destinazione \n");
    return -3;
  }
  while ((count = read(srcfd, buffer, 1024)) > 0) {
    write(dstfd, buffer, count);
  }
  fprintf(stdout, "%s", "File scritto con successo \n");
  close(srcfd);
  close(dstfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a6 <main+0x46>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b9 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x414(%rbp)
cmp    $0xffffffff,%eax
jne    11ee <main+0x8e>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12b9 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
call   1080 <creat@plt>
mov    %eax,-0x418(%rbp)
cmp    $0xffffffff,%eax
jne    1236 <main+0xd6>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    12b9 <main+0x159>
jmp    123b <main+0xdb>
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x41c(%rbp)
cmp    $0x0,%eax
jle    127e <main+0x11e>
mov    -0x418(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x41c(%rbp),%edx
call   1030 <write@plt>
jmp    123b <main+0xdb>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
lea    0xd9f(%rip),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x414(%rbp),%edi
call   1040 <close@plt>
mov    -0x418(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x3,%edi
jne    1222 <main+0xc2>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1241 <main+0xe1>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1080 <creat@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0x100>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11f0 <main+0x90>
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jg     11d0 <main+0x70>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
lea    0xe2d(%rip),%rdx
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %r15d,%edi
call   1040 <close@plt>
jmp    127d <main+0x11d>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    127d <main+0x11d>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xfffffffe,%r14d
jmp    127d <main+0x11d>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xfffffffd,%r14d
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"Errore \0A\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"Errore sorgente \0A\00"
@O_RDWR = global i32 0
@.str.2 = [22 x i8] c"Errore destinazione \0A\00"
@stdout = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [28 x i8] c"File scritto con successo \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %53
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %7
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %53
25: ; preds = %15
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_RDWR
%30 = call i32 @creat(i8* %28, i32 %29)
store i32 %30, i32* %8
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 -3, i32* %3
br label %53
35: ; preds = %25
br label %36
36: ; preds = %41, %35
%37 = load i32, i32* %7
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 1024)
store i32 %39, i32* %9
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i32, i32* %8
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%44 = load i32, i32* %9
%45 = call i32 @write(i32 %42, i8* %43, i32 %44)
br label %36
46: ; preds = %36
%47 = load i32, i32* @stdout
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* %7
%50 = call i32 @close(i32 %49)
%51 = load i32, i32* %8
%52 = call i32 @close(i32 %51)
store i32 0, i32* %3
br label %53
53: ; preds = %46, %32, %22, %12
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [9 x i8] c"Errore \0A\00"
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"Errore sorgente \0A\00"
@O_RDWR = global i32 0
@.str.2 = [22 x i8] c"Errore destinazione \0A\00"
@stdout = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [28 x i8] c"File scritto con successo \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %40
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 @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %40
18: ; preds = %9
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDWR
%22 = tail call i32 @creat(i8* %20, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = call i32 @read(i32 %13, i8* %4, i32 1024)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %30, label %35
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %40
30: ; preds = %24, %30
%31 = phi i32 [ %33, %30 ], [ %25, %24 ]
%32 = call i32 @write(i32 %22, i8* %4, i32 %31)
%33 = call i32 @read(i32 %13, i8* %4, i32 1024)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %30, label %35
35: ; preds = %30, %24
%36 = load i32, i32* @stdout
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%38 = tail call i32 @close(i32 %13)
%39 = tail call i32 @close(i32 %22)
br label %40
40: ; preds = %35, %27, %15, %6
%41 = phi i32 [ -1, %6 ], [ -2, %15 ], [ -3, %27 ], [ 0, %35 ]
ret i32 %41
}